package com.gitee.wsl.common.ui.ext

import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.NativePaint
import androidx.compose.ui.graphics.Paint
import androidx.compose.ui.graphics.PathEffect

expect fun Paint.blur(radius: Float)

expect fun NativePaint.setMaskFilter(blurRadius: Float)

expect fun NativePaint.setBlendMode(blendMode: BlendMode)

fun Paint.withOpacity(opacity: Float, action: (Paint) -> Unit) {
    val previousOpacity = alpha
    alpha *= opacity
    action(this)
    alpha = previousOpacity
}

fun Paint.appendPathEffect(effect: PathEffect) {
    if (pathEffect == null) {
        pathEffect = effect
    } else {
        pathEffect = PathEffect.chainPathEffect(effect, pathEffect!!)
    }
}